package cn.zc.controller.user;

import cn.zc.context.UserContext;
import cn.zc.entity.CourceStudentVo;
import cn.zc.entity.CourceVo;
import cn.zc.entity.LateTimeCource;
import cn.zc.entity.Qiandao;
import cn.zc.result.Result;
import cn.zc.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/user")
@Slf4j
//@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.PATCH, RequestMethod.OPTIONS})
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/cource")
    public Result<List<CourceStudentVo>> getCources(String studentId) {
//        String studentId = UserContext.getUser();
        List<CourceStudentVo> courcesByStudentId = userService.getCourcesByStudentId(studentId);
        return Result.success(courcesByStudentId);
    }
    @PostMapping("/qiandao")
    public Result qiandao(@RequestBody Qiandao period){
//        int value = LocalDate.now().getDayOfWeek().getValue();
        if(period.getWeekday()!=LocalDate.now().getDayOfWeek().getValue()) {
            return Result.success(false);
        }
        String time = period.getPeriod();
        boolean time1 = userService.isTime(time);
            if(time1){
            userService.periodQiandao(period);
        }
        return Result.success(time1);
    }
    @GetMapping("/overtime")
    public Result  overtime (String studentId){
        List<LateTimeCource> overtime = userService.overtime(studentId);
        return Result.success(overtime);
    }
}